package org.vnl.platform.web.impl.myfaces.dojo.component.tag;

import javax.el.ValueExpression;

import javax.faces.component.UIComponent;

import org.apache.commons.lang3.StringUtils;
import org.vnl.platform.web.impl.myfaces.dojo.IDojoConstants;
import org.vnl.platform.web.impl.myfaces.dojo.component.DojoForm;


public class DojoFormTag extends DojoTag {

    private ValueExpression target;
    
    @Override
    public String getComponentType() {
        return IDojoConstants.COMPONENT_FORM_TYPE;
    }

    @Override
    public String getRendererType() {
        return IDojoConstants.COMPONENT_FORM_TYPE;
    }

    @Override
    protected void setProperties(UIComponent arg0) {
        super.setProperties(arg0);
        if (arg0 instanceof DojoForm) {
            String dojoId = getDojoIdValue();
            if (!StringUtils.isBlank(dojoId)) {
                ((DojoForm) arg0).setDojoId(dojoId);
            }
            if (target != null) {
                Object obj = target.getValue(getELContext());
                if (obj != null) 
                    ((DojoForm) arg0).setTarget(obj.toString());
            }
        }
    }

    public ValueExpression getTarget() {
        return target;
    }

    public void setTarget(ValueExpression target) {
        this.target = target;
    }
    
}
